package com.oocl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.oocl.dao.AreasDao;
import com.oocl.pojo.Area;
import com.oocl.test.util.DBUtil;

public class AreasDaoImpl implements AreasDao{

	public List<Area> searchByAreasByAreaName(String areaName) throws SQLException {
		String sql="select * from areas where area like ?";
		String condition = "%"+areaName+"%";
		//System.out.println(condition);
		List<Area> list=new ArrayList<Area>();
		Connection conn=DBUtil.createConnection();
		PreparedStatement pst=null;
		ResultSet rs=null;
		pst=conn.prepareStatement(sql);
		pst.setString(1, condition);
		rs=pst.executeQuery();
		while(rs.next()){
			Area a=new Area();
			a.setId(rs.getInt("id"));
			a.setAreaid(rs.getString("areaid"));
			a.setArea(rs.getString("area"));
			a.setCityid("cityid");
			list.add(a);
		}
		DBUtil.close(conn, pst, rs);
		return list;
	}

	public List<String> serchAreasNamesByAreaName(String areaName) throws SQLException {
		String sql="select * from areas where area like ?";
		String condition = "%"+areaName+"%";
		//System.out.println(condition);
		List<String> list=new ArrayList<String>();
		Connection conn=DBUtil.createConnection();
		PreparedStatement pst=null;
		ResultSet rs=null;
		pst=conn.prepareStatement(sql);
		pst.setString(1, condition);
		rs=pst.executeQuery();
		while(rs.next()){
			list.add(rs.getString("area"));
		}
		DBUtil.close(conn, pst, rs);
		return list;
	}

}
